<template>
  <div>
    <!-- 头部 -->
    <pcNav ref="son"></pcNav>
    <div class="border"></div>
    <!-- 中间 -->
    <div class="centerBox" @click="ispop">
      <div class="mainBox">
        <div class="searchiptBox">
          <input type="text" class="iptBox" v-model="searchtitle" />
          <div class="searchBtn" @click="inputBtn"></div>
        </div>
        <div class="searchContent">
          <p>
            找到<span style="color: #f00"> {{ songMsg.length }} </span>首单曲
          </p>
          <div class="navBox">
            <div
              class="navList"
              v-for="(item, index) in navList"
              :key="index"
              @click="navClick(index)"
              :class="{ isactive: index == current }"
            >
              {{ item }}
            </div>
          </div>

          <div class="contentone" v-if="current == 0">
            <div
              class="contentList"
              :class="{ isactive1: index % 2 !== 0 }"
              v-for="(item, index) in songMsg"
              :key="index"
            >
              <div class="contentListleft">{{ item.name }}</div>
              <div class="contentListright">
                <span
                  v-for="(i, index) in item.artists.slice(0, 1)"
                  :key="index"
                  >{{ i.name }}</span
                >
                <span class="songzj">《{{ item.album.name }}》</span>
                <span>3:20</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <Footer></Footer>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      navList: [
        "单曲",
        "歌手",
        "专辑",
        "视频",
        "歌词",
        "歌单",
        "声音主播",
        "用户",
      ],
      current: 0,
      songMsg: [],
      searchtitle: "",
    };
  },
  methods: {
    navClick(index) {
      // console.log(index);
      this.current = index;
    },
    ispop() {
      this.$refs.son._data.isSecrah = false;
    },
    inputBtn() {
      if (this.searchtitle) {
        axios({
          url: "https://autumnfish.cn/search?",
          method: "get",
          params: {
            keywords: this.searchtitle,
            limit: 20,
            type: 1,
          },
        })
          .then((res) => {
            console.log(res);
            this.songMsg = res.data.result.songs;
            this.$refs.son._data.searchTitle = "";
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
    // 页面加载展示数据
    onShow() {
      if (this.searchtitle) {
        axios({
          url: "https://autumnfish.cn/search?",
          method: "get",
          params: {
            keywords: this.$refs.son._data.searchTitle,
            limit: 20,
            type: 1,
          },
        })
          .then((res) => {
            // console.log(res);
            this.songMsg = res.data.result.songs;
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
  },
  mounted() {
    // console.log(this.$route.params);

    this.$refs.son._data.searchTitle = this.$route.query.songName;
    this.searchtitle = this.$refs.son._data.searchTitle;
    this.onShow();
    // console.log(this.searchtitle);
  },
  updated() {},
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
.border {
  height: 5px;
  width: 100%;
  background-color: #c20c0c;
  border-bottom: 1px solid #a40011;
}
.centerBox {
  width: 100%;
  background: #f5f5f5;
}
.mainBox {
  box-sizing: border-box;
  width: 980px;
  background: #fff;
  margin: 0 auto;
  border: 1px solid #d3d3d3;
  border-width: 0 1px;
  padding: 40px;
  min-height: 700px;
}
.searchiptBox {
  width: 420px;
  height: 40px;
  margin: 0 auto;
  background: url(../assets/image/sprite.png) no-repeat 0 9999px;
  background-position: 0 0;
  display: flex;
  justify-content: space-between;
}
.iptBox {
  width: 320px;
  height: 17px;
  margin: 12px 0 0 20px;
  background: #fff;
  border: none;
  font-size: 12px;
  color: #333;
}
.searchBtn {
  width: 50px;
  height: 40px;
  cursor: pointer;
}
.searchContent {
  width: 100%;
  font-size: 12px;
  color: #333;
  margin-top: 30px;
}
.navBox {
  margin-top: 15px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: #f8f8f8;
  height: 39px;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
}
.navList {
  width: 12.5%;
  box-sizing: border-box;
  text-align: center;
  line-height: 39px;
  border-top: 2px solid #ccc;
  cursor: pointer;
  border-bottom: 1px solid #ccc;
  font-size: 14px;
}
.navList:hover {
  border-top: 2px solid #d13030;
}
.isactive {
  box-sizing: border-box;
  border-bottom: none;
  border-top: 2px solid #d13030;
  background: #fff;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
}
.isactive:first-child {
  border-left: none;
}
.isactive:last-child {
  border-right: none;
}
.isactive1 {
  background: #f7f7f7;
}
.contentone {
  width: 100%;
  margin-top: 20px;
  box-sizing: border-box;
}
.contentList {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  border: 1px solid #fff;
}
.contentListleft {
  box-sizing: border-box;
  width: 58%;
  padding: 12px 20px 12px 15px;
  color: #0c73c2;
}
.contentListright {
  width: 42%;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding-right: 30px;
  align-items: center;
}
.contentListright span:first-child {
  width: 20%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.songzj {
  width: 40%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  color: #666;
}
.contentList:hover {
  background: #f2f2f2;
  border: 1px solid #e1e1e1;
}
</style>